package com.gaoding.shared.dict.sdk.listen;

import com.gaoding.shared.dict.sdk.cache.DefaultCacheManage;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.core.Ordered;

/**
 * @author ：西格
 * @date ：Created in 2021-02-24
 * description ：初始化时调用
 */
public class Startup implements CommandLineRunner, Ordered {
    private final Boolean enable;

    public Startup(Boolean enable) {
        this.enable = enable;
    }

    /**
     * 初始化字典sdk
     */
    public void init() {
        // 判断是否需要初始化，enable不配置或者为true则需要初始化
        if (!Boolean.FALSE.equals(enable)) {
            DefaultCacheManage.init();
        }
    }

    /**
     * add by mobai
     * 会在整个spring容器启动完成后去做加载动作，保证不会出现死锁问题
     */
    @Override
    public void run(String... args) throws Exception {
        this.init();
    }

    @Override
    public int getOrder() {
        return Integer.MIN_VALUE;
    }
}
